﻿using UnityEngine;

public static class ApplicationPath
{
    /// <summary>
    /// 部分方法不能在子线程调用，所有路径都先初始化好
    /// </summary>
    static ApplicationPath()
    {
        PlatformName = GetPlatformName();
        BundleVersionFile = "resversion.bin";
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR

            ABCachePath = Application.dataPath + "/Assetbundles/" + PlatformName + "/";
            UnZipPath = Application.dataPath + "/Assetbundles/";
            DownloadTempPath = Application.dataPath + "/DownloadTempPath/";        
#else
            ABCachePath = Application.persistentDataPath + "/Assetbundles/" + PlatformName + "/";
            UnZipPath = Application.persistentDataPath + "/Assetbundles/";
            DownloadTempPath = Application.persistentDataPath + "/DownloadTempPath/";
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
        StreamingAssetsPath = Application.streamingAssetsPath;
#else
        StreamingAssetsPath = "file://" + Application.streamingAssetsPath;
#endif

        WWWStreamingAssetsABPath = StreamingAssetsPath + "/Assetbundles/" + PlatformName + "/";
        FileStreamingAssetsABPath = Application.streamingAssetsPath + "/Assetbundles/" + PlatformName + "/";
    }

    public static string BundleInfoFile { get { return PlatformName + ".bin"; } }
    public static string BundleZipFile { get { return PlatformName + ".zip"; } }

    public static string UnZipPath { get; private set; }
    public static string BundleVersionFile { get; private set; }
    public static string VersionInfoFile = "versionInfo.txt";
    public static string ProjectFile = "project.json";
    public static string MacAddressFile = "address.txt";
    /// <summary>
    /// 获取平台名称
    /// </summary>
    public static string PlatformName { get; private set; } = string.Empty;

    /// <summary>
    /// 获取缓存目录
    /// </summary>
    public static string ABCachePath { get; private set; } = string.Empty;

    /// <summary>
    /// 获取下载临时文件目录
    /// </summary>
    public static string DownloadTempPath { get; private set; } = string.Empty;

    /// <summary>
    /// 当前平台StreamingAssetsPath目录
    /// </summary>
    public static string StreamingAssetsPath { get; private set; } = string.Empty;
    /// <summary>
    /// 获取www streamingassets ab目录
    /// </summary>
    public static string WWWStreamingAssetsABPath { get; private set; } = string.Empty;
    /// <summary>
    /// 获取file streamingassets ab目录
    /// </summary>
    public static string FileStreamingAssetsABPath { get; private set; } = string.Empty;

    public static string GetPlatformName()
    {
#if UNITY_EDITOR
        switch (UnityEditor.EditorUserBuildSettings.activeBuildTarget)
        {
            case UnityEditor.BuildTarget.Android:
                return "android";
            case UnityEditor.BuildTarget.iOS:
                return "ios";
            case UnityEditor.BuildTarget.StandaloneWindows:
                return "windows";
            case UnityEditor.BuildTarget.StandaloneWindows64:
                return "windows";
        }
#else
            switch (Application.platform)
            {
                case RuntimePlatform.WindowsPlayer:
                    return "windows";
                case RuntimePlatform.IPhonePlayer:
                    return "ios";
                case RuntimePlatform.Android:
                    return "android";
                default:
                    Debug.LogError("该平台没有实现");
                    break;
            }
#endif
        return string.Empty;
    }
}
